package com.lib.entity;

import com.lib.common.Constant;

public class JsonResult<T> {

    private Integer state; // 响应状态码
    private String msg; // 响应消息
    private T data; // 响应数据

    // 快速创建一个正常响应、不携带数据的JsonResult对象
    public static JsonResult<Void> getSuccessJR(){
        return new JsonResult<>(Constant.JSON_STATE_SUCCESS,"OK");
    }
    // 快速创建一个正常响应、携带数据的JsonResult对象
    public static <T> JsonResult<T> getSuccessJR(T data){
        return new JsonResult<>(Constant.JSON_STATE_SUCCESS,"OK",data);
    }

    public JsonResult() {
    }

    public JsonResult(Integer state, String msg) {
        this.state = state;
        this.msg = msg;
    }

    public JsonResult(Integer state, String msg, T data) {
        this.state = state;
        this.msg = msg;
        this.data = data;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "JsonResult{" +
                "state=" + state +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
